package com.dgut.event;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class MyEventListener implements ApplicationListener<MyEvent> {
    private static final Logger logger = LoggerFactory.getLogger(MyEventListener.class);

    @Override
    public void onApplicationEvent(MyEvent myEvent) {
        logger.info("事件监听器监听到事件MyEvent, 休眠当前线程2秒！");
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("MyEvent事件的message属性为：{}",myEvent.getMessage());
    }
}
